package com.anysoft.ui.activity;

import com.anysoft.R;
import com.anysoft.base.BaseBaseActivity;
import com.anysoft.base.BasePresenter;
import com.anysoft.manager.PermissionManager;
import com.anysoft.ui.activity.web.TouristsActivity;
import com.anysoft.utils.ActivityCollector;
import com.anysoft.utils.StatusBarUtil;

import java.util.Timer;
import java.util.TimerTask;

/**
 * Created by LiTingYao on 2018/5/26.
 */
public class SplashActivity extends BaseBaseActivity implements PermissionManager.OnPermissionListener {
    private static final int COUNT_DOWN_SECOND = 2;
    
    @Override
    protected BasePresenter createPresenter() {
        return null;
    }
    
    @Override
    protected int provideContentViewId() {
        return  R.layout.activity_splash_layout;
    }
    
    @Override
    protected void doBeforeSetContentView() {
        super.doBeforeSetContentView();
        StatusBarUtil.fullScreen(this);
    }
    
    @Override
    public void initView() {
        super.initView();
        firstEvent();
    }
    
    @Override
    public void initData() {
        super.initData();
    }
    
    @Override
    public void initListener() {
        super.initListener();
    }
    
    @Override
    protected void onDestroy() {
        super.onDestroy();
    }
    
    private void firstEvent() {
        if (PermissionManager.getInstance().checkPermissions(this, PermissionManager.PERMISSION_ALL_STATE)) {
            startLoginActivity();
        } else {
            PermissionManager.getInstance().requestPermissions(this, PermissionManager.REQUEST_ALL_STATE,
                    PermissionManager.PERMISSION_ALL_STATE, this);
        }
    }
    
    @Override
    public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        PermissionManager.onRequestPermissionsResult(requestCode, permissions, grantResults);
    }
    
    @Override
    public void onPermissionSuccess() {
        startLoginActivity();
    }
    
    @Override
    public void onPermissionFail() {
        startLoginActivity();
    }
    
    public void startLoginActivity(){
        Timer timer = new Timer();
        timer.schedule(new TimerTask() {
            public void run() {
                ActivityCollector.startTargetActivity(SplashActivity.this,TouristsActivity.class);
                finish();
            }
        }, COUNT_DOWN_SECOND * 1000);// 设定指定的时间time
    }
}
